#include <stdio.h>
#include <stdlib.h>

#include "queue.h"

struct QUEUE_ITEM {
    int value;
    TAILQ_ENTRY(QUEUE_ITEM) entry;
};

static TAILQ_HEAD(,QUEUE_ITEM) queue_head;
//static TAILQ_HEAD(,QUEUE_ITEM) queue_head = TAILQ_HEAD_INITIALIZER();

int main(int argc, char *argv[])
{
    int i = 0;
    struct QUEUE_ITEM *item;
    struct QUEUE_ITEM *tmp_item;

    TAILQ_INIT(&queue_head);

    if (TAILQ_EMPTY(&queue_head))
        printf("queue is empty\n");

    for( i = 0; i < 10; i += 1)
    {
        item = (struct QUEUE_ITEM *)malloc(sizeof(struct QUEUE_ITEM));
        item->value = i;
        //TAILQ_INSERT_HEAD(&queue_head, item, entry);
        TAILQ_INSERT_TAIL(&queue_head, item, entry);
    }

    printf("after insert 10 item to queue:\n");
    TAILQ_FOREACH(item, &queue_head, entry)
        printf("item value = %d\n", item->value);

    TAILQ_FOREACH(tmp_item, &queue_head, entry)
    {
        if(tmp_item->value % 2 != 0)
            TAILQ_REMOVE(&queue_head, tmp_item, entry);
    }

    printf("after delete 5 items from queue:\n");
    TAILQ_FOREACH(item, &queue_head, entry)
        printf("item value = %d\n", item->value);

    return 0;
}

